/*******************************************\
|					    |
| This displays the Easy Level high scores  |
|					    |
| Called with int score.		    |
|					    |
| 					    |
\*******************************************/

#include <ncurses.h>
#include <stdio.h>
#include <string.h>

FILE *fp;

// Inserts the new highscore and prints the high score list from ./highscore_list_e.txt

int easy_score(char name[], int score)
{
	int x, y;
	char i, buffer[20];
	
	clear();

	/* Prints header for high score screen. */
	mvprintw(2, (getmaxx(stdscr)/2) - 5, "HIGH SCORES");
	mvprintw(3, (getmaxx(stdscr)/2) - 5, "LEVEL: EASY");
	refresh();

	// Opens highscore list to append. Change location to fit your needs.
	fp = fopen("/home/students/j.pitel/the_Commuter/highscore_list_e.txt", "a");
		
	fprintf(fp, "%s\t\t%6d", name, score);

	fclose(fp);
	
	system("./enter_easy.sh");

	x = 1;
	y = 5;

	// Opens highscore list to read. Change location to fit your needs.
	fp = fopen("/home/students/j.pitel/the_Commuter/highscore_list_e.txt", "r");

	while(fgets(buffer, 15, fp) != NULL)	// Reads and writes the txt file
	{
		y++;
		mvprintw(y, x, "%s", buffer);
	}	

	fclose(fp);

	mvprintw(23, 1, "Press q to continue.");
	refresh();

	while((i = getch()) != 'q') {}	

	return;	
}


int highscore_easy(int score)
{

	char buffer[20], name[3];
	clear();

	mvprintw(5, 7, "Please enter your initials (xxx): "); //asks for user name
	refresh();
	getstr(name);
	
	easy_score(name, score);

	
	return;
}
